package org.saxion.saktiehuis.aspect;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.saxion.saktiehuis.model.UserSession;
import org.saxion.saktiehuis.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.ui.Model;

@Configurable
@Aspect
public class NavigationAspect {

	@Autowired
	private ProductCategoryService productCategoryService;
	@Autowired
	UserSession session;

	@After("execution(* org.saxion.saktiehuis.*.*(..,Model)) && args(..,model)  ")
	public void navigation(Model model) throws Throwable {
		model.addAttribute("categories",
				productCategoryService.getProductCategories());
		model.addAttribute("loggedIn",
				session.isLoggedIn());
		model.addAttribute("username",
				session.getUsername());
//		System.out.println("Model: " + model);
	}
}